home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / rasthresh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  1.4 KB  |  62 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3.  
  4. har           *progname;
  5. har           *filename;
  6. ixrect        *pr1, *pr2;
  7.  
  8. #ifdef STANDALONE
  9. ain(argc, argv, envp)
  10. #else
  11. asthresh_main(argc, argv, envp)
  12. #endif
  13.     int             argc;
  14.     char          **argv;
  15.     char          **envp;
  16. {
  17.     register int    i, j;
  18.     int             levels;
  19.     int             threshold;
  20.     colormap_t        colormap;
  21.  
  22.     threshold = -1;
  23.     progname = strsave(argv[0]);
  24.     parse_profile(&argc, argv, envp);
  25.  
  26.     while ((gc = getopt(argc, argv, "t:")) != EOF)
  27.         switch (gc) {
  28.         case 't':
  29.             threshold = atoi(optarg);
  30.             break;
  31.         case '?':
  32.             errflag++;
  33.             break;
  34.         }
  35.  
  36.     if (errflag)
  37.         error((char *) 0, "Usage: %s: [-t threshold] [infile] [outfile]\n", progname);
  38.  
  39.     for (stream = 0; optind < argc; stream++, optind++)
  40.         if (stream < 2 && strcmp(argv[optind], "-") != 0)
  41.             if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
  42.                 error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
  43.  
  44.     if ((pr1 = pr_load(stdin, &colormap)) == NULL)
  45.         error(PR_IO_ERR_RASREAD);
  46.  
  47.     if (threshold == -1) {
  48.         if (bitrestrict)
  49.             threshold = (calc_max(pr1)+1) / 2;
  50.         else
  51.             threshold = MAXLEVEL(pr1->pr_depth) / 2;
  52.     }
  53.     if ((pr2 = mem_create(pr1->pr_size.x, pr1->pr_size.y, 1)) == NULL)
  54.         error("mem_create returned NULL");
  55.  
  56.     for (j = 0; j < pr1->pr_size.y; j++)
  57.         for (i = 0; i < pr1->pr_size.x; i++)
  58.             pr_put(pr2, i, j, (pr_get(pr1, i, j) > threshold) ? 1 : 0);
  59.  
  60.     pr_dump(pr2, stdout, &colormap, RT_STANDARD, 0);
  61. }
  62.